package com.shuiyun.service.impl;

import com.shuiyun.dao.UserMapper;
import com.shuiyun.entity.User;
import com.shuiyun.service.SysUserService;
import com.shuiyun.utils.DataGridResult;
import com.shuiyun.utils.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService{
    @Resource
    private UserMapper userMapper;
    @Override
    public DataGridResult findAllUser(Query query) {
        if(query.get("search")==null){
             query.put("search","");
        }
        List<User> list = userMapper.findUserByPage(query);
        long total = userMapper.findTotalCount(query);
        DataGridResult result = new DataGridResult(list,Integer.parseInt(total+""));
        return result;
    }

    @Override
    public int add(User user) {
        return userMapper.insert(user);
    }

    @Override
    public User selectUserById(long userId) {
        return userMapper.selectByPrimaryKey((int)userId);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int deleteBatch(Long[] ids) {
        return userMapper.deleteBatch(ids);
    }

    @Override
    public List<User> findAllUserNoPage() {
        return userMapper.findAll();
    }
}
